//
//  AppDelegate.m
//  projectOfTeamSample
//
//  Created by lk on 15/11/16.
//  Copyright © 2015年 liukai. All rights reserved.
//

#import "AppDelegate.h"
#import "SurnameController.h"
#import "ChatListController.h"
#import "UserDetaileTableViewController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    
    /**
     
     * 设置UIWindow的属性
     
     **/
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    
    /**
     
     * 设置根视图控制器
     
     **/
    
    
    // 初始化TableViewController
    UITabBarController *TBC = [[UITabBarController alloc] init];
    
    // 自定义TBC.viewControlls
    SurnameController *surnameVC = [[SurnameController alloc] init];
    ChatListController *chatVC = [[ChatListController alloc] init];
    UserDetaileTableViewController *userVC = [[UserDetaileTableViewController alloc] init];
    
    // 设置viewController.tabBarItem
    surnameVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"糗事" image:[UIImage imageNamed:@"surname"] tag:0];
    chatVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"聊天" image:[UIImage imageNamed:@"chat"] tag:1];
    userVC.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"用户" image:[UIImage imageNamed:@"user"] tag:2];
    
    // 设置navagationController
    UINavigationController *surnameNC = [[UINavigationController alloc] initWithRootViewController:surnameVC];
    UINavigationController *chatNC = [[UINavigationController alloc] initWithRootViewController:chatVC];
    UINavigationController *userNC = [[UINavigationController alloc] initWithRootViewController:userVC];
    
    // 设置TBC.viewControlls
    TBC.viewControllers = @[surnameNC, chatNC, userNC];
    
    // 设置tabBar的颜色
    TBC.tabBar.tintColor = [UIColor blackColor];
    
    // 设置window的根视图控制器，并将TableViewController作为navigationController的根视图控制器
    self.window.rootViewController = TBC;
    
#pragma mark-设置LeanCloud初始化SDK
    [AVOSCloud setApplicationId:@"mfsPcmjnebWBeO36cKsASx7T"
                      clientKey:@"Kh5S75vfFQuuBpuzSNMSSumr"];
    
    //    如果想跟踪统计应用的打开情况，后面还可以添加下列代码：
    
    [AVAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
    
    // Override point for customization after application launch.
    
#pragma mark-当前状态
    
    [AVUser currentUser];
    
#pragma mark -- 通信模块

    //测试是否连接api
    AVObject *post = [AVObject objectWithClassName:@"TestObject"];
    [post setObject:@"Hello,World!" forKey:@"words"];
    [post saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (succeeded) {
            // 保存成功了！
        }
    }];

    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
